<?php

defined('BASEPATH') or die('forbidden');

class Configvalue {

    function __construct() {
        $framework = &get_instance('controller');
        $this->db = &$framework->db;
        $this->cache = &$framework->cache;
    }

    function _init() {
        //加载缓存
        $result = $this->cache->get("configvalue");
        if (!$result) {
            $result = array();
            $this->db->query("SELECT * FROM {pre}configvalue");
            while ($row = $this->db->get_array()) {
                $result[strtolower($row['id'])] = $row['content'];
            }
            $this->cache->set("configvalue", $result);
        }
        $this->configvalueData = $result;
    }

    /**
     * 读取配置信息
     * @param string $id
     * @return string
     */
    function get_configvalue($id) {
        $id = strtolower($id);
        if (is_array($id)) {
            $last = array();
            foreach ($id as $m => $n) {
                $last[$n] = isset($this->configvalueData[$n]) ? $this->configvalueData[$n] : '';
            }
        } else {
            $last = isset($this->configvalueData[$id]) ? $this->configvalueData[$id] : '';
        }
        return $last;
    }

}